{extend name="public:base"}
{block name='css'}
<link href="__PUBLIC__/css/plugins/iCheck/custom.css" rel="stylesheet">
{/block}
{block name='body'}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <form method="post" class="form-horizontal" id="commentForm" onsubmit="return false;" action="" >
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>{empty name='data'}添加{else/}编辑{/empty}通知</h5>
                    <input type="submit" class="btn btn-primary" style="margin-left: 50px;" value="保存"/>
                    <a href="{:url('index')}" class="btn btn-sm btn-primary pull-right m-t-n-xs">返回</a>
                </div>
                <div class="ibox-content">

                    <input type="hidden" name="id" value="{$data.id|default=''}">

                    <div class="form-group">
                        <label class="col-sm-2 control-label">标题</label>
                        <div class="col-sm-8">
                            <input type="text" name="title" value="{$data.title|default=''}" placeholder="请输入标题" class="input-sm form-control">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">内容</label>
                        <div class="col-sm-8">
                            <textarea id="content" name="content" placeholder="请输入内容" type="text/plain" style="width:100%;height:200px;">{$data.content|default=''}</textarea>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-2">
                            <input class="btn btn-primary" type="submit" value="保存内容" />
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
    </form>
</div>
</body>
{/block}
{block name="js"}
<script src="__PUBLIC__/js/content.min.js?v=1.0.0"></script>
<script src="__PUBLIC__/js/plugins/validate/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/plugins/validate/messages_zh.min.js"></script>
<script type="text/javascript">

    $.validator.setDefaults({
        highlight: function(e) {
            $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
        },
        success: function(e) {
            e.closest(".form-group").removeClass("has-error").addClass("has-success")
        },
        errorElement: "span",
        errorPlacement: function(e, r) {
            e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
        },
        errorClass: "help-block m-b-none",
        validClass: "help-block m-b-none"
    });
    $().ready(function() {
        $('select[name=user_type]').change();
        var e = "<i class='fa fa-times-circle'></i> ";
        $("#commentForm").validate({
            rules: {
                title: "required",
                content: 'required'
            },
            messages: {
                title: e + "请输入标题",
                content: e + "请输入内容"
            },
            submitHandler: function(form){
                if ($(form).hasClass('ed')) {
                    return false;
                }

                $(form).addClass('ed');
                $.post('', $(form).serialize(), function(data){
                    layer.msg(data.info);
                    if (data.status == 'y') {
                        setTimeout(function(){window.location.href = '{:url("index")}';},1500);
                    } else {
                        $(form).removeClass('ed');
                    }
                }, 'json');
            },
            invalidHandler: function(form, validator) {  //不通过回调
                return false;
            }
        })
    });
</script>
{/block}
